package com.sfy.designdemo.policyandfactory.context;

import com.sfy.designdemo.policyandfactory.service.IPayment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Created by SiFeiYang on Date 2022/4/6
 */
@Component
public class PayContext {

    @Autowired
    private ApplicationContext applicationContext;
    private IPayment iPayment;


    public PayContext() {
    }

    public PayContext(IPayment iPayment) {
        this.iPayment=iPayment;
    }

    public IPayment getIPayment() {
        return iPayment;
    }

    public void setIPayment(IPayment iPayment) {
        this.iPayment = iPayment;
    }

    public IPayment getiPaymentByType(String paymentType){
        return applicationContext.getBean(paymentType,IPayment.class);
    }
}
